
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.PreventionType;
import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskPrevention;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class TaskPreventionServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected TaskPreventionService service;

	/**
	 * Instantiates a new TaskPreventionServiceTest.
	 *
	 */
	public TaskPreventionServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Return a count of all TaskPrevention entity
	* 
	 */
	@Test
	public void countTaskPreventions() {
		Integer response = null;
		response = service.countTaskPreventions();
		// TODO: JUnit - Add assertions to test outputs of operation: countTaskPreventions
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteTaskPreventionTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPreventionTask 
		Integer taskprevention_id = 0;
		Integer related_task_id = 0;
		TaskPrevention response = null;
		response = service.deleteTaskPreventionTask(taskprevention_id, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTaskPreventionTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing TaskPrevention entity
	* 
	 */
	@Test
	public void deleteTaskPrevention() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPrevention 
		TaskPrevention taskprevention = new cn.edu.scau.cmi.hombio.domain.TaskPrevention();
		service.deleteTaskPrevention(taskprevention);
	}

	/**
	 * Operation Unit Test
	* Return all TaskPrevention entity
	* 
	 */
	@Test
	public void findAllTaskPreventions() {
		// TODO: JUnit - Populate test inputs for operation: findAllTaskPreventions 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<TaskPrevention> response = null;
		response = service.findAllTaskPreventions(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllTaskPreventions
	}

	/**
	 * Operation Unit Test
	* Save an existing PreventionType entity
	* 
	 */
	@Test
	public void saveTaskPreventionPreventionType() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPreventionPreventionType 
		Integer id = 0;
		PreventionType related_preventiontype = new cn.edu.scau.cmi.hombio.domain.PreventionType();
		TaskPrevention response = null;
		response = service.saveTaskPreventionPreventionType(id, related_preventiontype);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTaskPreventionPreventionType
	}

	/**
	 * Operation Unit Test
	* Save an existing TaskPrevention entity
	* 
	 */
	@Test
	public void saveTaskPrevention() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPrevention 
		TaskPrevention taskprevention_1 = new cn.edu.scau.cmi.hombio.domain.TaskPrevention();
		service.saveTaskPrevention(taskprevention_1);
	}

	/**
	 * Operation Unit Test
	* Load an existing TaskPrevention entity
	* 
	 */
	@Test
	public void loadTaskPreventions() {
		Set<TaskPrevention> response = null;
		response = service.loadTaskPreventions();
		// TODO: JUnit - Add assertions to test outputs of operation: loadTaskPreventions
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findTaskPreventionByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findTaskPreventionByPrimaryKey 
		Integer id_1 = 0;
		TaskPrevention response = null;
		response = service.findTaskPreventionByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findTaskPreventionByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveTaskPreventionTask() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPreventionTask 
		Integer id_2 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		TaskPrevention response = null;
		response = service.saveTaskPreventionTask(id_2, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTaskPreventionTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing PreventionType entity
	* 
	 */
	@Test
	public void deleteTaskPreventionPreventionType() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPreventionPreventionType 
		Integer taskprevention_id_1 = 0;
		Integer related_preventiontype_id = 0;
		TaskPrevention response = null;
		response = service.deleteTaskPreventionPreventionType(taskprevention_id_1, related_preventiontype_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTaskPreventionPreventionType
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
